#include <iostream>
#include <vector>
#include "Thread.hpp"
#include <unistd.h>
#include "Mutex.hpp"
#include "Cond.hpp"

const int thread_cnt = 5;

int test_cnt = 0;
MutexModule::Mutex mutex;
CondModule::Cond cond;
void TestFunc()
{
    while (true)
    {
        MutexModule::MutexGuard lock(mutex);
        cond.Wait(mutex);
        std::cout << "test_cnt = " << test_cnt << " " << std::endl;
        if(test_cnt > 10)
            break;
    }
}
int main()
{
    std::vector<ThreadModule::Thread> threads;

    for (int i = 0; i < thread_cnt; i++)
    {
        threads.emplace_back(TestFunc);
    }

    for (auto &thread : threads)
    {
        thread.Start();
    }

    while(true)
    {
        test_cnt++;
        cond.Signal();
        if(test_cnt == 20)
            break;
        sleep(1);
    }

    for (auto &thread : threads)
    {
        thread.Join();
    }
}